#!/usr/local/bin/python3
# -*- coding: utf-8 -*-

"""
@File    :demo.py
@Author  :keyin
@Time    :2021-01-31 10:50
"""
from os.path import join

import cv2
import numpy
import os

path = os.path.abspath('.')
path = join(path, '1.jpg')


def find(img):
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)  # 转化为灰度图
    blur = cv2.GaussianBlur(gray, (3, 3), 0)  # 用高斯滤波处理原图像降噪
    canny = cv2.Canny(blur, 20, 30)  # 20是最小阈值,50是最大阈值 边缘检测
    kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (3, 3))
    dilation = cv2.dilate(canny, kernel, iterations=1)  # 膨胀一下，来连接边缘
    contours, hierarchy = cv2.findContours(dilation, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)  # 找边框
    cv2.drawContours(img, contours, -1, (0, 255, 0), 10)
    p1 = ()
    p2 = ()
    p3 = ()
    p4 = ()
    pp = [p1, p2, p3, p4]

    return pp

# 创建图像
I = numpy.zeros((3501,2500),dtype = numpy.uint8)
I[:]=255
I = cv2.cvtColor(I,cv2.COLOR_GRAY2BGR)
img = cv2.imread(path)
y,x = img.shape[0:2]
# imga = find(img)
# ya, xa = imga.shape[0:2]

cv2.imshow('1',img)
cv2.waitKey(0)
cv2.destroyAllWindows()

